/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			prefs.cc
  \date			Aug 2012
  \author		TNick

  \brief		Contains the implementation of Prefs class


*//*


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read COPYING and README files in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<cpg/cpg.h>

#include	<QSettings>
#include	<QColor>
#include	<usermsg.h>

#include	"prefs.h"


/*  INCLUDES    ============================================================ */
//
//
//
//
/*  DEFINITIONS    --------------------------------------------------------- */

#define	i_stgs_s_(i)	stgs_s_[i-INTERNAL__FIRST_STRING]
#define	i_stgs_i_(i)	stgs_i_[i-INTERNAL__FIRST_INTEGER]
#define	i_stgs_r_(i)	stgs_r_[i-INTERNAL__FIRST_REAL]


/*  DEFINITIONS    ========================================================= */
//
//
//
//
/*  DATA    ---------------------------------------------------------------- */

Prefs *			Prefs::uniq_ = NULL;

/*  DATA    ================================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

/* ------------------------------------------------------------------------- */
Prefs::Prefs	( void )
	: PrefBase(), MemTrack()
{

	Q_ASSERT( uniq_ == NULL );
	uniq_ = this;

	str_.set(
				&stgs_s_[0],
				&defaults_s_[0],
				COUNT_STRINGS,
				INTERNAL__FIRST_STRING,
				START_STRINGS
				);

	int_.set(
				&stgs_i_[0],
				&defaults_i_[0],
				COUNT_INTS,
				INTERNAL__FIRST_INTEGER,
				START_INTS
				);

	real_.set(
				&stgs_r_[0],
				&defaults_r_[0],
				COUNT_REALS,
				INTERNAL__FIRST_REAL,
				START_REALS
				);

	p_stgs_names_ = &pref_names_[0];
	stgs_prefix_ = "AppPreferences/" CPG_VER_STR;
	load();
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
Prefs::~Prefs	( void )
{
	save();
	Q_ASSERT( uniq_ != NULL );
	uniq_ = NULL;
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
bool			Prefs::init						( void )
{
	if ( uniq_ == NULL )
		new Prefs;
	return true;
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void			Prefs::end						( void )
{
	if ( uniq_ == NULL )
		return;
	delete uniq_;
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
Prefs::Id		Prefs::byName						( const QString & s_name )
{
	VarTypes	vty;
	unsigned	idx;
	return (Prefs::Id)uniq_->PrefBase::byName( s_name, vty, idx );
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
QString			Prefs::toString			( qreal val )
{
	return QString::number(
				val,
				uniq_->i_stgs_i_( REAL_FORMAT ),
				uniq_->i_stgs_i_( REAL_PRECISION )
				);
}
/* ========================================================================= */

/*  CLASS    =============================================================== */
//
//
//
//
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
